// 角色管理
module.exports = app => {
    const DataTypes = app.Sequelize;
    const SysRole = app.model.define('SysRole', {
        id: {
            type: DataTypes.INTEGER(11).UNSIGNED,
            allowNull: false,
            primaryKey: true,
            autoIncrement: true,
        },
        shop_id: {
            type: DataTypes.INTEGER(11),
            allowNull: true,
            defaultValue: null,
            comment: '商家ID，预留SASS功能'
        },
        name: {
            type: DataTypes.STRING(60),
            allowNull: false,
            defaultValue: '',
            comment: '角色名'
        },
        cate: {
            type: DataTypes.INTEGER(1).UNSIGNED,
            allowNull: false,
            defaultValue: '0',
            comment: '0=>商城系统角色, 1=>为分系统预留能力'
        },
        is_super_admin: {
            type: DataTypes.INTEGER(1).UNSIGNED,
            allowNull: false,
            defaultValue: 0,
            comment: '是否超级管理员0否1是'
        },
        remark: {
            type: DataTypes.STRING(60),
            allowNull: false,
            defaultValue: '',
            comment: '备注'
        },
        is_delete: {
            type: DataTypes.INTEGER(1).UNSIGNED,
            allowNull: false,
            defaultValue: '0',
            comment: '是否删除，0->存在，1->删除'
        },
    }, {
        tableName: 'sys_role'
    });
    SysRole.associate = function () {
        SysRole.hasMany(app.model.SysUserRole, {
            as: 'UserRole',
            foreignKey: 'role_id',
            constraints: false,
        });
    };

    return SysRole;
};
